﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using PPWMS.DBUtility;
using PPWMS.Model;
namespace PPWMS.DAL
{
    /// <summary>
    /// 数据访问类:Subpack
    /// </summary>
    public partial class Subpack
    {
        public Subpack()
        { }
        #region  BasicMethod

        public string GetMaxSubpackId(string orderSubId)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT top 1 SubPackId  as 'maxSubpackId' ");
            sb.Append("FROM dbo.tb_Subpack ");
            if (!string.IsNullOrEmpty(orderSubId))
            {
                sb.Append("WHERE OrderSubId='" + orderSubId + "'");
            }
            string re = "";
            int rows = SQLHelper.Query(sb.ToString()).Tables[0].Rows.Count;
            if (rows > 0)
            {
                re = SQLHelper.Query(sb.ToString()).Tables[0].Rows[0]["maxSubpackId"].ToString().Trim();
                
                int index = int.Parse(re.Substring(re.Length - 2, 2));
                re = index.ToString("D2");
            }
            else
            {
                return "00";
            }
            return re;
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string SubPackId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tb_Subpack");
            strSql.Append(" where SubPackId=@SubPackId ");
            SqlParameter[] parameters = {
					new SqlParameter("@SubPackId", SqlDbType.VarChar,50)			};
            parameters[0].Value = SubPackId;

            return SQLHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(PPWMS.Model.SubpackModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into tb_Subpack(");
            strSql.Append("SubPackId,OrderSubId,OrderId,BoxId,ProdType,SailingDate,Destination,OutPlanDate,ProdSpeci,ProdDesc,Addi,FrameColor,LegType,MatchedInLeg,FootType,PanelSpeci,PanelFeature,PanelColor,BoardColor,BoardMaterial,EdgeColor,BackplaneColor,ChairType,ChairColor,SpecialTagsRemarks,IncludeItemsFlag,ItemsPerPack,OrderPackCount,TotalItemsCount,CheckedItemsCount,CompletedPackCount,LackedPackCount,PanelWeight,FrameWeight,Height,NetWeight,GrossWeight,Volume,Remark)");
            strSql.Append(" values (");
            strSql.Append("@SubPackId,@OrderSubId,@OrderId,@BoxId,@ProdType,@SailingDate,@Destination,@OutPlanDate,@ProdSpeci,@ProdDesc,@Addi,@FrameColor,@LegType,@MatchedInLeg,@FootType,@PanelSpeci,@PanelFeature,@PanelColor,@BoardColor,@BoardMaterial,@EdgeColor,@BackplaneColor,@ChairType,@ChairColor,@SpecialTagsRemarks,@IncludeItemsFlag,@ItemsPerPack,@OrderPackCount,@TotalItemsCount,@CheckedItemsCount,@CompletedPackCount,@LackedPackCount,@PanelWeight,@FrameWeight,@Height,@NetWeight,@GrossWeight,@Volume,@Remark)");
            SqlParameter[] parameters = {
					new SqlParameter("@SubPackId", SqlDbType.VarChar,50),
					new SqlParameter("@OrderSubId", SqlDbType.VarChar,50),
					new SqlParameter("@OrderId", SqlDbType.VarChar,50),
					new SqlParameter("@BoxId", SqlDbType.VarChar,50),
					new SqlParameter("@ProdType", SqlDbType.NVarChar,50),
					new SqlParameter("@SailingDate", SqlDbType.Date,3),
					new SqlParameter("@Destination", SqlDbType.NVarChar,500),
					new SqlParameter("@OutPlanDate", SqlDbType.Date,3),
					new SqlParameter("@ProdSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@ProdDesc", SqlDbType.NVarChar,-1),
					new SqlParameter("@Addi", SqlDbType.NVarChar,50),
					new SqlParameter("@FrameColor", SqlDbType.NVarChar,50),
					new SqlParameter("@LegType", SqlDbType.NVarChar,50),
					new SqlParameter("@MatchedInLeg", SqlDbType.NVarChar,50),
					new SqlParameter("@FootType", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelFeature", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardMaterial", SqlDbType.NVarChar,50),
					new SqlParameter("@EdgeColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BackplaneColor", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairType", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairColor", SqlDbType.NVarChar,50),
					new SqlParameter("@SpecialTagsRemarks", SqlDbType.NVarChar,500),
					new SqlParameter("@IncludeItemsFlag", SqlDbType.Int,4),
					new SqlParameter("@ItemsPerPack", SqlDbType.Int,4),
					new SqlParameter("@OrderPackCount", SqlDbType.Int,4),
					new SqlParameter("@TotalItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CheckedItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CompletedPackCount", SqlDbType.Int,4),
					new SqlParameter("@LackedPackCount", SqlDbType.Int,4),
					new SqlParameter("@PanelWeight", SqlDbType.Decimal,9),
					new SqlParameter("@FrameWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Height", SqlDbType.Int,4),
					new SqlParameter("@NetWeight", SqlDbType.Decimal,9),
					new SqlParameter("@GrossWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Volume", SqlDbType.Decimal,9),
					new SqlParameter("@Remark", SqlDbType.NVarChar,500)};
            parameters[0].Value = model.SubPackId;
            parameters[1].Value = model.OrderSubId;
            parameters[2].Value = model.OrderId;
            parameters[3].Value = model.BoxId;
            parameters[4].Value = model.ProdType;
            parameters[5].Value = model.SailingDate;
            parameters[6].Value = model.Destination;
            parameters[7].Value = model.OutPlanDate;
            parameters[8].Value = model.ProdSpeci;
            parameters[9].Value = model.ProdDesc;
            parameters[10].Value = model.Addi;
            parameters[11].Value = model.FrameColor;
            parameters[12].Value = model.LegType;
            parameters[13].Value = model.MatchedInLeg;
            parameters[14].Value = model.FootType;
            parameters[15].Value = model.PanelSpeci;
            parameters[16].Value = model.PanelFeature;
            parameters[17].Value = model.PanelColor;
            parameters[18].Value = model.BoardColor;
            parameters[19].Value = model.BoardMaterial;
            parameters[20].Value = model.EdgeColor;
            parameters[21].Value = model.BackplaneColor;
            parameters[22].Value = model.ChairType;
            parameters[23].Value = model.ChairColor;
            parameters[24].Value = model.SpecialTagsRemarks;
            parameters[25].Value = model.IncludeItemsFlag;
            parameters[26].Value = model.ItemsPerPack;
            parameters[27].Value = model.OrderPackCount;
            parameters[28].Value = model.TotalItemsCount;
            parameters[29].Value = model.CheckedItemsCount;
            parameters[30].Value = model.CompletedPackCount;
            parameters[31].Value = model.LackedPackCount;
            parameters[32].Value = model.PanelWeight;
            parameters[33].Value = model.FrameWeight;
            parameters[34].Value = model.Height;
            parameters[35].Value = model.NetWeight;
            parameters[36].Value = model.GrossWeight;
            parameters[37].Value = model.Volume;
            parameters[38].Value = model.Remark;

            int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PPWMS.Model.SubpackModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tb_Subpack set ");
            strSql.Append("OrderSubId=@OrderSubId,");
            strSql.Append("OrderId=@OrderId,");
            strSql.Append("BoxId=@BoxId,");
            strSql.Append("ProdType=@ProdType,");
            strSql.Append("SailingDate=@SailingDate,");
            strSql.Append("Destination=@Destination,");
            strSql.Append("OutPlanDate=@OutPlanDate,");
            strSql.Append("ProdSpeci=@ProdSpeci,");
            strSql.Append("ProdDesc=@ProdDesc,");
            strSql.Append("Addi=@Addi,");
            strSql.Append("FrameColor=@FrameColor,");
            strSql.Append("LegType=@LegType,");
            strSql.Append("MatchedInLeg=@MatchedInLeg,");
            strSql.Append("FootType=@FootType,");
            strSql.Append("PanelSpeci=@PanelSpeci,");
            strSql.Append("PanelFeature=@PanelFeature,");
            strSql.Append("PanelColor=@PanelColor,");
            strSql.Append("BoardColor=@BoardColor,");
            strSql.Append("BoardMaterial=@BoardMaterial,");
            strSql.Append("EdgeColor=@EdgeColor,");
            strSql.Append("BackplaneColor=@BackplaneColor,");
            strSql.Append("ChairType=@ChairType,");
            strSql.Append("ChairColor=@ChairColor,");
            strSql.Append("SpecialTagsRemarks=@SpecialTagsRemarks,");
            strSql.Append("IncludeItemsFlag=@IncludeItemsFlag,");
            strSql.Append("ItemsPerPack=@ItemsPerPack,");
            strSql.Append("OrderPackCount=@OrderPackCount,");
            strSql.Append("TotalItemsCount=@TotalItemsCount,");
            strSql.Append("CheckedItemsCount=@CheckedItemsCount,");
            strSql.Append("CompletedPackCount=@CompletedPackCount,");
            strSql.Append("LackedPackCount=@LackedPackCount,");
            strSql.Append("PanelWeight=@PanelWeight,");
            strSql.Append("FrameWeight=@FrameWeight,");
            strSql.Append("Height=@Height,");
            strSql.Append("NetWeight=@NetWeight,");
            strSql.Append("GrossWeight=@GrossWeight,");
            strSql.Append("Volume=@Volume,");
            strSql.Append("Remark=@Remark");
            strSql.Append(" where SubPackId=@SubPackId ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderSubId", SqlDbType.VarChar,50),
					new SqlParameter("@OrderId", SqlDbType.VarChar,50),
					new SqlParameter("@BoxId", SqlDbType.VarChar,50),
					new SqlParameter("@ProdType", SqlDbType.NVarChar,50),
					new SqlParameter("@SailingDate", SqlDbType.Date,3),
					new SqlParameter("@Destination", SqlDbType.NVarChar,500),
					new SqlParameter("@OutPlanDate", SqlDbType.Date,3),
					new SqlParameter("@ProdSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@ProdDesc", SqlDbType.NVarChar,-1),
					new SqlParameter("@Addi", SqlDbType.NVarChar,50),
					new SqlParameter("@FrameColor", SqlDbType.NVarChar,50),
					new SqlParameter("@LegType", SqlDbType.NVarChar,50),
					new SqlParameter("@MatchedInLeg", SqlDbType.NVarChar,50),
					new SqlParameter("@FootType", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelFeature", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardMaterial", SqlDbType.NVarChar,50),
					new SqlParameter("@EdgeColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BackplaneColor", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairType", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairColor", SqlDbType.NVarChar,50),
					new SqlParameter("@SpecialTagsRemarks", SqlDbType.NVarChar,500),
					new SqlParameter("@IncludeItemsFlag", SqlDbType.Int,4),
					new SqlParameter("@ItemsPerPack", SqlDbType.Int,4),
					new SqlParameter("@OrderPackCount", SqlDbType.Int,4),
					new SqlParameter("@TotalItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CheckedItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CompletedPackCount", SqlDbType.Int,4),
					new SqlParameter("@LackedPackCount", SqlDbType.Int,4),
					new SqlParameter("@PanelWeight", SqlDbType.Decimal,9),
					new SqlParameter("@FrameWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Height", SqlDbType.Int,4),
					new SqlParameter("@NetWeight", SqlDbType.Decimal,9),
					new SqlParameter("@GrossWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Volume", SqlDbType.Decimal,9),
					new SqlParameter("@Remark", SqlDbType.NVarChar,500),
					new SqlParameter("@SubPackId", SqlDbType.VarChar,50)};
            parameters[0].Value = model.OrderSubId;
            parameters[1].Value = model.OrderId;
            parameters[2].Value = model.BoxId;
            parameters[3].Value = model.ProdType;
            parameters[4].Value = model.SailingDate;
            parameters[5].Value = model.Destination;
            parameters[6].Value = model.OutPlanDate;
            parameters[7].Value = model.ProdSpeci;
            parameters[8].Value = model.ProdDesc;
            parameters[9].Value = model.Addi;
            parameters[10].Value = model.FrameColor;
            parameters[11].Value = model.LegType;
            parameters[12].Value = model.MatchedInLeg;
            parameters[13].Value = model.FootType;
            parameters[14].Value = model.PanelSpeci;
            parameters[15].Value = model.PanelFeature;
            parameters[16].Value = model.PanelColor;
            parameters[17].Value = model.BoardColor;
            parameters[18].Value = model.BoardMaterial;
            parameters[19].Value = model.EdgeColor;
            parameters[20].Value = model.BackplaneColor;
            parameters[21].Value = model.ChairType;
            parameters[22].Value = model.ChairColor;
            parameters[23].Value = model.SpecialTagsRemarks;
            parameters[24].Value = model.IncludeItemsFlag;
            parameters[25].Value = model.ItemsPerPack;
            parameters[26].Value = model.OrderPackCount;
            parameters[27].Value = model.TotalItemsCount;
            parameters[28].Value = model.CheckedItemsCount;
            parameters[29].Value = model.CompletedPackCount;
            parameters[30].Value = model.LackedPackCount;
            parameters[31].Value = model.PanelWeight;
            parameters[32].Value = model.FrameWeight;
            parameters[33].Value = model.Height;
            parameters[34].Value = model.NetWeight;
            parameters[35].Value = model.GrossWeight;
            parameters[36].Value = model.Volume;
            parameters[37].Value = model.Remark;
            parameters[38].Value = model.SubPackId;

            int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string SubPackId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tb_Subpack ");
            strSql.Append(" where SubPackId=@SubPackId ");
            SqlParameter[] parameters = {
					new SqlParameter("@SubPackId", SqlDbType.VarChar,50)			};
            parameters[0].Value = SubPackId;

            int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string SubPackIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tb_Subpack ");
            strSql.Append(" where SubPackId in (" + SubPackIdlist + ")  ");
            int rows = SQLHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PPWMS.Model.SubpackModel GetModel(string SubPackId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 SubPackId,OrderSubId,OrderId,BoxId,ProdType,SailingDate,Destination,OutPlanDate,ProdSpeci,ProdDesc,Addi,FrameColor,LegType,MatchedInLeg,FootType,PanelSpeci,PanelFeature,PanelColor,BoardColor,BoardMaterial,EdgeColor,BackplaneColor,ChairType,ChairColor,SpecialTagsRemarks,IncludeItemsFlag,ItemsPerPack,OrderPackCount,TotalItemsCount,CheckedItemsCount,CompletedPackCount,LackedPackCount,PanelWeight,FrameWeight,Height,NetWeight,GrossWeight,Volume,Remark from tb_Subpack ");
            strSql.Append(" where SubPackId=@SubPackId ");
            SqlParameter[] parameters = {
					new SqlParameter("@SubPackId", SqlDbType.VarChar,50)			};
            parameters[0].Value = SubPackId;

            PPWMS.Model.SubpackModel model = new PPWMS.Model.SubpackModel();
            DataSet ds = SQLHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PPWMS.Model.SubpackModel DataRowToModel(DataRow row)
        {
            PPWMS.Model.SubpackModel model = new PPWMS.Model.SubpackModel();
            if (row != null)
            {
                if (row["SubPackId"] != null)
                {
                    model.SubPackId = row["SubPackId"].ToString();
                }
                if (row["OrderSubId"] != null)
                {
                    model.OrderSubId = row["OrderSubId"].ToString();
                }
                if (row["OrderId"] != null)
                {
                    model.OrderId = row["OrderId"].ToString();
                }
                if (row["BoxId"] != null)
                {
                    model.BoxId = row["BoxId"].ToString();
                }
                if (row["ProdType"] != null)
                {
                    model.ProdType = row["ProdType"].ToString();
                }
                if (row["SailingDate"] != null && row["SailingDate"].ToString() != "")
                {
                    model.SailingDate = DateTime.Parse(row["SailingDate"].ToString());
                }
                if (row["Destination"] != null)
                {
                    model.Destination = row["Destination"].ToString();
                }
                if (row["OutPlanDate"] != null && row["OutPlanDate"].ToString() != "")
                {
                    model.OutPlanDate = DateTime.Parse(row["OutPlanDate"].ToString());
                }
                if (row["ProdSpeci"] != null)
                {
                    model.ProdSpeci = row["ProdSpeci"].ToString();
                }
                if (row["ProdDesc"] != null)
                {
                    model.ProdDesc = row["ProdDesc"].ToString();
                }
                if (row["Addi"] != null)
                {
                    model.Addi = row["Addi"].ToString();
                }
                if (row["FrameColor"] != null)
                {
                    model.FrameColor = row["FrameColor"].ToString();
                }
                if (row["LegType"] != null)
                {
                    model.LegType = row["LegType"].ToString();
                }
                if (row["MatchedInLeg"] != null)
                {
                    model.MatchedInLeg = row["MatchedInLeg"].ToString();
                }
                if (row["FootType"] != null)
                {
                    model.FootType = row["FootType"].ToString();
                }
                if (row["PanelSpeci"] != null)
                {
                    model.PanelSpeci = row["PanelSpeci"].ToString();
                }
                if (row["PanelFeature"] != null)
                {
                    model.PanelFeature = row["PanelFeature"].ToString();
                }
                if (row["PanelColor"] != null)
                {
                    model.PanelColor = row["PanelColor"].ToString();
                }
                if (row["BoardColor"] != null)
                {
                    model.BoardColor = row["BoardColor"].ToString();
                }
                if (row["BoardMaterial"] != null)
                {
                    model.BoardMaterial = row["BoardMaterial"].ToString();
                }
                if (row["EdgeColor"] != null)
                {
                    model.EdgeColor = row["EdgeColor"].ToString();
                }
                if (row["BackplaneColor"] != null)
                {
                    model.BackplaneColor = row["BackplaneColor"].ToString();
                }
                if (row["ChairType"] != null)
                {
                    model.ChairType = row["ChairType"].ToString();
                }
                if (row["ChairColor"] != null)
                {
                    model.ChairColor = row["ChairColor"].ToString();
                }
                if (row["SpecialTagsRemarks"] != null)
                {
                    model.SpecialTagsRemarks = row["SpecialTagsRemarks"].ToString();
                }
                if (row["IncludeItemsFlag"] != null && row["IncludeItemsFlag"].ToString() != "")
                {
                    model.IncludeItemsFlag = int.Parse(row["IncludeItemsFlag"].ToString());
                }
                if (row["ItemsPerPack"] != null && row["ItemsPerPack"].ToString() != "")
                {
                    model.ItemsPerPack = int.Parse(row["ItemsPerPack"].ToString());
                }
                if (row["OrderPackCount"] != null && row["OrderPackCount"].ToString() != "")
                {
                    model.OrderPackCount = int.Parse(row["OrderPackCount"].ToString());
                }
                if (row["TotalItemsCount"] != null && row["TotalItemsCount"].ToString() != "")
                {
                    model.TotalItemsCount = int.Parse(row["TotalItemsCount"].ToString());
                }
                if (row["CheckedItemsCount"] != null && row["CheckedItemsCount"].ToString() != "")
                {
                    model.CheckedItemsCount = int.Parse(row["CheckedItemsCount"].ToString());
                }
                if (row["CompletedPackCount"] != null && row["CompletedPackCount"].ToString() != "")
                {
                    model.CompletedPackCount = int.Parse(row["CompletedPackCount"].ToString());
                }
                if (row["LackedPackCount"] != null && row["LackedPackCount"].ToString() != "")
                {
                    model.LackedPackCount = int.Parse(row["LackedPackCount"].ToString());
                }
                if (row["PanelWeight"] != null && row["PanelWeight"].ToString() != "")
                {
                    model.PanelWeight = Double.Parse(row["PanelWeight"].ToString());
                }
                if (row["FrameWeight"] != null && row["FrameWeight"].ToString() != "")
                {
                    model.FrameWeight = Double.Parse(row["FrameWeight"].ToString());
                }
                if (row["Height"] != null && row["Height"].ToString() != "")
                {
                    model.Height = int.Parse(row["Height"].ToString());
                }
                if (row["NetWeight"] != null && row["NetWeight"].ToString() != "")
                {
                    model.NetWeight = Double.Parse(row["NetWeight"].ToString());
                }
                if (row["GrossWeight"] != null && row["GrossWeight"].ToString() != "")
                {
                    model.GrossWeight = Double.Parse(row["GrossWeight"].ToString());
                }
                if (row["Volume"] != null && row["Volume"].ToString() != "")
                {
                    model.Volume = Double.Parse(row["Volume"].ToString());
                }
                if (row["Remark"] != null)
                {
                    model.Remark = row["Remark"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            /*
             select SubPackId, OrderSubId,OrderId,BoxId,ProdType,SailingDate,Destination,OutPlanDate,ProdSpeci,ProdDesc,Addi,FrameColor,LegType,MatchedInLeg,FootType,PanelSpeci,PanelFeature,PanelColor,BoardColor,BoardMaterial,EdgeColor,BackplaneColor,ChairType,ChairColor,SpecialTagsRemarks,IncludeItemsFlag,ItemsPerPack,OrderPackCount,TotalItemsCount,CheckedItemsCount,CompletedPackCount,LackedPackCount,PanelWeight,FrameWeight,Height,NetWeight,GrossWeight,Volume,Remark 
             * 
             * SELECT SubPackId '订单分包号', OrderSubId  '订单分序号',OrderId '订单号',BoxId '箱号',ProdType '产品类别',SailingDate '船期',Destination '目的地',OutPlanDate '出柜周计划',ProdSpeci '产品名称规格',ProdDesc '产品描述',Addi '附件',FrameColor '框架颜色',LegType '腿类型',MatchedInLeg '配套内腿',FootType '脚类型',PanelSpeci '面板规格',PanelFeature '面板特点',PanelColor '面板颜色',BoardColor '台面颜色',BoardMaterial '台面材质',EdgeColor '封边颜色',BackplaneColor '背板颜色',ChairType '椅壳类型',ChairColor '椅壳颜色',SpecialTagsRemarks '特别标签备注',IncludeItemsFlag '分体配件项数',ItemsPerPack '每包件数',OrderPackCount '订单数量',TotalItemsCount '总件数',CheckedItemsCount '验算件数',CompletedPackCount '完成数量',LackedPackCount '尚缺数量',PanelWeight '面板重量',FrameWeight '框架重量',Height '高度',NetWeight '净重',GrossWeight '毛重',Volume '立方数',Remark '备注'
             */
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT SubPackId '订单分包号', OrderSubId  '订单分序号',OrderId '订单号',BoxId '箱号',ProdType '产品类别',SailingDate '船期',Destination '目的地',OutPlanDate '出柜周计划',ProdSpeci '产品名称规格',ProdDesc '产品描述',Addi '附件',FrameColor '框架颜色',LegType '腿类型',MatchedInLeg '配套内腿',FootType '脚类型',PanelSpeci '面板规格',PanelFeature '面板特点',PanelColor '面板颜色',BoardColor '台面颜色',BoardMaterial '台面材质',EdgeColor '封边颜色',BackplaneColor '背板颜色',ChairType '椅壳类型',ChairColor '椅壳颜色',SpecialTagsRemarks '特别标签备注',IncludeItemsFlag '分体配件项数',ItemsPerPack '每包件数',OrderPackCount '订单数量',TotalItemsCount '总件数',CheckedItemsCount '验算件数',CompletedPackCount '完成数量',LackedPackCount '尚缺数量',PanelWeight '面板重量',FrameWeight '框架重量',Height '高度',NetWeight '净重',GrossWeight '毛重',Volume '立方数',Remark '备注' ,'修改' '修改','删除' '删除' ");
            strSql.Append(" FROM tb_Subpack ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(SubpackModel Order)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  SubPackId '订单分包号', OrderSubId  '订单分序号',OrderId  '订单号',BoxId '箱号',ProdType '产品类别',SailingDate '船期',Destination '目的地',OutPlanDate '出柜周计划',ProdSpeci '产品名称规格',ProdDesc '产品描述',Addi '附件',FrameColor '框架颜色',LegType '腿类型',MatchedInLeg '配套内腿',FootType '脚类型',PanelSpeci '面板规格',PanelFeature '面板特点',PanelColor '面板颜色',BoardColor '台面颜色',BoardMaterial '台面材质',EdgeColor '封边颜色',BackplaneColor '背板颜色',ChairType '椅壳类型',ChairColor '椅壳颜色',SpecialTagsRemarks '特别标签备注',IncludeItemsFlag '分体配件项数',ItemsPerPack '每包件数',OrderPackCount '订单数量',TotalItemsCount '总件数',CheckedItemsCount '验算件数',CompletedPackCount '完成数量',LackedPackCount '尚缺数量',PanelWeight '面板重量',FrameWeight '框架重量',Height '高度',NetWeight '净重',GrossWeight '毛重',Volume '立方数',Remark '备注','修改' '修改','删除' '删除' ");
            strSql.Append(" FROM tb_Subpack where 1=1 ");
            if (!string.IsNullOrEmpty(Order.SubPackId))
            {
                strSql.Append(" and  SubPackId like  '%" + Order.SubPackId + "%'");
            }
            if (!string.IsNullOrEmpty(Order.OrderSubId))
            {
                strSql.Append(" and  OrderSubId like  '%" + Order.OrderSubId + "%'");
            }
            if (!string.IsNullOrEmpty(Order.OrderId))
            {
                strSql.Append(" and  OrderId like  '%" + Order.OrderId + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BoxId))
            {
                strSql.Append(" and  BoxId like  '%" + Order.BoxId + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ProdType))
            {
                strSql.Append(" and  ProdType like  '%" + Order.ProdType + "%'");
            }
            if (!string.IsNullOrEmpty(Order.SailingDate.ToString()))
            {
                strSql.Append(" and  SailingDate like  '%" + Order.SailingDate.ToString() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.Destination))
            {
                strSql.Append(" and  Destination like  '%" + Order.Destination + "%'");
            }
            if (!string.IsNullOrEmpty(Order.OutPlanDate.ToString()))
            {
                strSql.Append(" and  OutPlanDate like  '%" + Order.OutPlanDate.ToString() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ProdSpeci))
            {
                strSql.Append(" and  ProdSpeci like  '%" + Order.ProdSpeci + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ProdDesc))
            {
                strSql.Append(" and  ProdDesc like  '%" + Order.ProdDesc + "%'");
            }
            if (!string.IsNullOrEmpty(Order.Addi))
            {
                strSql.Append(" and  Addi like  '%" + Order.Addi + "%'");
            }
            if (!string.IsNullOrEmpty(Order.FrameColor))
            {
                strSql.Append(" and  FrameColor like  '%" + Order.FrameColor + "%'");
            }
            if (!string.IsNullOrEmpty(Order.LegType))
            {
                strSql.Append(" and  LegType like  '%" + Order.LegType + "%'");
            }
            if (!string.IsNullOrEmpty(Order.MatchedInLeg))
            {
                strSql.Append(" and  MatchedInLeg like  '%" + Order.MatchedInLeg + "%'");
            }
            if (!string.IsNullOrEmpty(Order.FootType))
            {
                strSql.Append(" and  FootType like  '%" + Order.FootType + "%'");
            }
            if (!string.IsNullOrEmpty(Order.PanelSpeci))
            {
                strSql.Append(" and  PanelSpeci like  '%" + Order.PanelSpeci + "%'");
            }
            if (!string.IsNullOrEmpty(Order.PanelFeature))
            {
                strSql.Append(" and  PanelFeature like  '%" + Order.PanelFeature + "%'");
            }
            if (!string.IsNullOrEmpty(Order.PanelColor))
            {
                strSql.Append(" and  PanelColor like  '%" + Order.PanelColor + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BoardColor))
            {
                strSql.Append(" and  BoardColor like  '%" + Order.BoardColor + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BoardMaterial))
            {
                strSql.Append(" and  BoardMaterial like  '%" + Order.BoardMaterial + "%'");
            }
            if (!string.IsNullOrEmpty(Order.EdgeColor))
            {
                strSql.Append(" and  EdgeColor like  '%" + Order.EdgeColor + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BackplaneColor))
            {
                strSql.Append(" and  BackplaneColor like  '%" + Order.BackplaneColor + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ChairType))
            {
                strSql.Append(" and  ChairType like  '%" + Order.ChairType + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ChairColor))
            {
                strSql.Append(" and  ChairColor like  '%" + Order.ChairColor + "%'");
            }
            if (!string.IsNullOrEmpty(Order.SpecialTagsRemarks))
            {
                strSql.Append(" and  SpecialTagsRemarks like  '%" + Order.SpecialTagsRemarks + "%'");
            }
            if (Order.IncludeItemsFlag != null)
            {
                strSql.Append(" and  IncludeItemsFlag = " + Order.IncludeItemsFlag);
            }
            if (Order.ItemsPerPack != null)
            {
                strSql.Append(" and  ItemsPerPack = " + Order.ItemsPerPack);
            }
            if (Order.OrderPackCount != null)
            {
                strSql.Append(" and  OrderPackCount = " + Order.OrderPackCount);
            }
            if (Order.TotalItemsCount != null)
            {
                strSql.Append(" and  TotalItemsCount = " + Order.TotalItemsCount);
            }
            if (Order.CheckedItemsCount != null)
            {
                strSql.Append(" and  CheckedItemsCount = " + Order.CheckedItemsCount);
            }
            if (Order.CompletedPackCount != null)
            {
                strSql.Append(" and  CompletedPackCount = " + Order.CompletedPackCount);
            }
            if (Order.LackedPackCount != null)
            {
                strSql.Append(" and  LackedPackCount = " + Order.LackedPackCount);
            }
            if (Order.PanelWeight != null)
            {
                strSql.Append(" and  PanelWeight = " + Order.PanelWeight);
            }
            if (Order.FrameWeight != null)
            {
                strSql.Append(" and  FrameWeight = " + Order.FrameWeight);
            }
            if (Order.Height != null)
            {
                strSql.Append(" and  Height = " + Order.Height);
            }
            if (Order.NetWeight != null)
            {
                strSql.Append(" and  NetWeight = " + Order.NetWeight);
            }
            if (Order.GrossWeight != null)
            {
                strSql.Append(" and  GrossWeight = " + Order.GrossWeight);
            }
            if (Order.Volume != null)
            {
                strSql.Append(" and  Volume = " + Order.Volume);
            }
            if (!string.IsNullOrEmpty(Order.Remark))
            {
                strSql.Append(" and  Remark like  '%" + Order.Remark + "%'");
            }

            return SQLHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" SubPackId,OrderSubId,OrderId,BoxId,ProdType,SailingDate,Destination,OutPlanDate,ProdSpeci,ProdDesc,Addi,FrameColor,LegType,MatchedInLeg,FootType,PanelSpeci,PanelFeature,PanelColor,BoardColor,BoardMaterial,EdgeColor,BackplaneColor,ChairType,ChairColor,SpecialTagsRemarks,IncludeItemsFlag,ItemsPerPack,OrderPackCount,TotalItemsCount,CheckedItemsCount,CompletedPackCount,LackedPackCount,PanelWeight,FrameWeight,Height,NetWeight,GrossWeight,Volume,Remark ");
            strSql.Append(" FROM tb_Subpack ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return SQLHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM tb_Subpack ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = SQLHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.SubPackId desc");
            }
            strSql.Append(")AS Row, T.*  from tb_Subpack T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return SQLHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "tb_Subpack";
            parameters[1].Value = "SubPackId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return SQLHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod

    }
}

